package me.edzh.spring.bootstrap.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import java.util.HashMap;
import java.util.Map;

@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class UmengPushModel {
    private String appkey;
    private String timestamp;
    private String type;
    private String device_tokens;
    private String alias_type;
    private String alias;
    private String file_id;
    private String filter;
    private Map<String, Object> payload;


    private String production_mode;
    private String description;
    private String mipush;
    private String mi_activity;

    @JsonIgnore
    public void setIOSPushPayload(String title, String message, Map<String, String> extras) {
        payload = new HashMap<String, Object>(){{
            put("aps", new HashMap<String, Object>(){{
                put("alert", new HashMap<String, Object>(){{
                    put("title", title);
                    put("body", message);
                }});
            }});

            if (extras != null) {
                var entries = extras.entrySet();
                for (var e : entries) {
                    put(e.getKey(), e.getValue());
                }
            }
        }};

    }

    @JsonIgnore
    public void setAndroidPushPayload(String title, String message, Map<String, String> extras) {
        payload = new HashMap<String, Object>(){{
            put("display_type", "notification");
            put("body", new HashMap<String, Object>(){{
                put("ticker", "你有一条通知");
                put("title", title);
                put("text", message);
            }});

            if (extras != null) {
                put("extra", new HashMap<String, Object>(){{
                    var entries = extras.entrySet();
                    for (var e : entries) {
                        put(e.getKey(), e.getValue());
                    }
                }});
            }
        }};

    }
}
